package com.tiger.userClient.http.feedback;

import com.tiger.db.entity.FeedbackRecord;
import com.tiger.userClient.Db;
import com.tiger.userClient.interceptor.RequireAuth;
import com.tiger.utils.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import java.time.Instant;


@RestController
@RequestMapping("/feedback")
public class FeedBackController {

    private final Db db;

    public FeedBackController(Db db) {
        this.db = db;
    }

    @RequireAuth
    @PostMapping("submit")
    public Object submit(@RequestBody() FeedbackRecord data, @RequestAttribute(value = "userId", required = false) Long userId, @RequestAttribute(value = "role", required = false) String role) {

        if(data.getContent() == null || data.getContent().isEmpty()) return ResponseUtil.successRes();
        data.setUserId(userId);

        Instant now = Instant.now();

        data.setCreateTime(now.getEpochSecond());

        db.feedbackRecord.save(data);

        return ResponseUtil.successRes();


    }
}
